feat: implement entry for BTreeMap similar to std lib#420
feat: implement entry for BTreeMap similar to std lib#420hpeebles wants to merge 18 commits intodfinity:mainfrom
entry for BTreeMap similar to std lib#420Conversation
|
|
|
|
|
|
# Conflicts: # src/btreemap.rs
| NodeType::Internal => { | ||
| match node.search(key, self.memory()) { | ||
| Ok(idx) => { | ||
| // Case 2: The node is an internal node and the key exists in it. |
There was a problem hiding this comment.
This logic is unchanged, it has just moved to remove_from_internal_node so that it can be used within entry.rs
| NodeType::Leaf => { | ||
| match node.search(key, self.memory()) { | ||
| Ok(idx) => { | ||
| // Case 1: The node is a leaf node and the key exists in it. |
There was a problem hiding this comment.
This logic is unchanged, it has just moved to remove_from_leaf_node so that it can be used within entry.rs
|
The |
|
The benchmarks are failing because there are 2 new benchmarks. I'm holding off on regenerating the files though until the PR has been approved, so that reviewers have a chance to see the results of the benchmarks. |
This allows you to lookup an entry by searching the map, then modify the value and insert it back into the map without having to search again.
The API is similar to
entryon the std libBTreeMap, but is not able to return mutable references, so you need to either useand_modifyor get the owned value, update it, then insert it back in the entry.For example in the std lib you would write this
Or using the shorthand syntax
Whereas using this new API for
StableBTreeMapyou would write it as thisOr using the shorthand syntax
I've added some benchmarks which compare using
gettheninsertvs usingentryfor 10k u32 values, from the results you can see that in this scenario usingentryis roughly 37% faster